package com.liuceng.rabbitmq.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.remoting.support.RemoteInvocation;
import org.springframework.remoting.support.RemoteInvocationResult;
import org.springframework.stereotype.Service;

/**
 * Created by yanwen on 16-11-28.
 */
@Service
public class RabbitmqService {
    @Autowired
    private AmqpTemplate amqpTemplate;

    public void getRabbitmq(String input){
        System.out.println(input);
    }

    public void send(){
        for(int i=0;i<10;i++){
            amqpTemplate.convertAndSend("exchangeTest", "queueTest",
                    "消息"+i);
        }
    }

    public void  getInfo(){
        RemoteInvocationResult result = (RemoteInvocationResult) amqpTemplate
                .convertSendAndReceive("dev.info",new RemoteInvocation("getInfo"
                        ,new Class[]{String.class},new Object[]{"客户端2"}));
        System.out.println(result.getValue());
    }

}
